﻿// ************************************************* //
// QFNAdapter.cs
// Author: Chris Wu
// Email: cwu@dataio.com
// ------------------------------------ //
// version 1.0 - Initial Create
// date: April 25th, 2010
// ------------------------------------ //
//
// ************************************************* //

using System;

namespace Common
{
    /// <summary>
    /// Description of QFNAdapter.
    /// </summary>
    public class QFNAdapter
    {
        // ********************************************** //
        // pin assignment array (6 x 13) //

        //   38 x x x x x x x x x x x 26    //
        // 1                             25 //
        // x                             x  //
        // x              x              x  //
        // x                             x  //
        // x                             x  //
        // 6                             20 //
        //   7  x x x x x x x x x x x 19    //

        // ********************************************** //

        private int m_PinMapId;            // PinMapId
        private int m_RowNum;               // RowNum
        private int m_ColumnNum;            // ColumnNum
        private int m_TotalPins;            // Total defined Pins
        private string[] m_PositionList;    // PositionList
        private string[] m_LabelList;       // LableList

        // QFNAdapter Constructor
        public QFNAdapter()
        {
            m_RowNum = 0;
            m_ColumnNum = 0;
            m_TotalPins = 0;
            m_PositionList = null;
            m_LabelList = null;
        }

        // get and set m_PinMapId
        public int PinMapId
        {
            get { return m_PinMapId; }
            set { m_PinMapId = value; }
        }

        // get and set m_TotalPins
        public int TotalPins
        {
            get { return m_TotalPins; }
            set { m_TotalPins = value; }
        }

        // get and set m_RowNum
        public int RowNum
        {
            get { return m_RowNum; }
            set { m_RowNum = value; FillPositionList(); }
        }

        // get and set m_ColumnNum
        public int ColumnNum
        {
            get { return m_ColumnNum; }
            set { m_ColumnNum = value; FillPositionList(); }
        }

        // get and set m_PositionList
        public string[] PositionList
        {
            get { return m_PositionList; }
            set { m_PositionList = value; }
        }

        // get and set m_LabelList
        public string[] LabelList
        {
            get { return m_LabelList; }
            set { m_LabelList = value; }
        }

        // function FillPositionList
        // according to the parameters m_RowNum and m_Column to fill the PositionList
        // in the meantime to set initial string for LabelList
        private void FillPositionList()
        {
            m_PositionList = new string[(m_RowNum + m_ColumnNum) * 2 + 1];
            m_LabelList = new string[(m_RowNum + m_ColumnNum) * 2 + 1];
            for (int i = 0; i < (m_RowNum + m_ColumnNum) * 2 + 1; i++)
            {
                m_PositionList[i] = (i + 1).ToString();
                m_LabelList[i] = "";
            }

            return;
        }

        // get m_PositionList[index]
        public string GetPosition(int index)
        {
            string str = "";
            if (index > (m_RowNum + m_ColumnNum) * 2 || index < 0)
            {
                // there is no index record
                return str;
            }

            str = m_PositionList[index];

            return str;
        }

        // set m_LabelList[index] with label
        public void SetLabelList(int index, string label)
        {
            if (index > (m_RowNum + m_ColumnNum) * 2 || index < 0)
            {
                // there is no index record
                return;
            }

            m_LabelList[index] = label;

            return;
        }

        // get m_LabelList[index]
        public string GetLabel(int index)
        {
            string str = "";
            if (index > (m_RowNum + m_ColumnNum) * 2 || index < 0)
            {
                // there is no index record
                return str;
            }

            str = m_LabelList[index];

            return str;
        }
    }
}
